package main.java.easy;

import java.util.Stack;

/**
 * @Author: 郑国荣
 * @Date: 2023-07-10-11:28
 * @Description: 有效的括号
 */
public class ValidParentheses {
    public boolean isValid(String s){
        Stack<Character> characters = new Stack<>();
        for (char c : s.toCharArray()) {
            if (c == '(') characters.push(')');
            else if (c == '{') characters.push('}');
            else if (c == ']') characters.push(']');
            else if (characters.isEmpty() || c != characters.pop()) {
                return false;
            }
        }
        return characters.isEmpty();
    }
}
